package main

import (
	"fmt"
	"log"
	// "net/http"
	"os"

	pdf "github.com/adrg/go-wkhtmltopdf"
)

func main() {
	pdf.Init()
	defer pdf.Destroy()

	// h := http.FileServer("./")

	// Create object from file.
	object, err := pdf.NewObject("./御才网.html")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(3)

	// object.Header.ContentCenter = "[title]"
	// object.Header.DisplaySeparator = true

	// // Create object from URL.
	// object2, err := pdf.NewObject("https://google.com")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// object.Footer.ContentLeft = "[date]"
	// object.Footer.ContentCenter = "Sample footer information"
	// object.Footer.ContentRight = "[page]"
	// object.Footer.DisplaySeparator = true

	// Create object from reader.
	// inFile, err := os.Open("sample2.html")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// defer inFile.Close()

	// object3, err := pdf.NewObjectFromReader(inFile)
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// object3.Zoom = 1.5
	// object3.TOC.Title = "Table of Contents"

	// Create converter.
	converter, err := pdf.NewConverter()
	if err != nil {
		log.Fatal(err)
	}
	defer converter.Destroy()

	// Add created objects to the converter.
	converter.Add(object)
	// converter.Add(object2)
	// converter.Add(object3)

	// Set converter options.
	converter.Title = "Sample document"
	converter.PaperSize = pdf.A4
	converter.Orientation = pdf.Landscape
	converter.MarginTop = "1cm"
	converter.MarginBottom = "1cm"
	converter.MarginLeft = "10mm"
	converter.MarginRight = "10mm"

	// Convert objects and save the output PDF document.
	outFile, err := os.Create("out.pdf")
	if err != nil {
		log.Fatal(err)
	}
	defer outFile.Close()

	if err := converter.Run(outFile); err != nil {
		log.Fatal(err)
	}
}
